package collection;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Created by chenxin34 on 2018/10/6 下午5:44.
 */
public class ListCopyChangeTest {
    public static void main(String[] args) {
        List<MyObject> myObjectList = new ArrayList<>();
        MyObject foo = new MyObject("123");
        myObjectList.add(foo);

        MyObject bar = new MyObject("456");
        myObjectList.add(bar);
        System.out.println(JSON.toJSONString(myObjectList));

        bar.setS("890");

        System.out.println(JSON.toJSONString(myObjectList));

        List<MyObject> myObjectListCopy = new ArrayList<>(myObjectList);
        bar.setS("000");

        myObjectListCopy.get(0).setS("111");
        System.out.println(JSON.toJSONString(myObjectList));
        System.out.println(JSON.toJSONString(myObjectListCopy));
    }

    private static class MyObject {
        private String s;

        public MyObject(String s) {
            this.s = s;
        }

        public String getS() {
            return s;
        }

        public void setS(String s) {
            this.s = s;
        }
    }
}
